import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.firsthomework.R

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MainScreen()
        }
    }
}

@Composable
fun MainScreen() {
    var showText by remember { mutableStateOf(false) }

    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(16.dp),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Center
    ) {
        // 显示国旗图片
        Image(
            painter = painterResource(id = R.drawable.flag),
            contentDescription = stringResource(id = R.string.app_name),
            modifier = Modifier
                .size(150.dp)
                .padding(bottom = 16.dp),
            contentScale = ContentScale.Crop
        )

        // 显示 "Hello, World!"
        Text(
            text = stringResource(id = R.string.hello_world),
            modifier = Modifier.padding(bottom = 16.dp)
        )

        // 按钮
        Button(onClick = { showText = !showText }) {
            Text(text = stringResource(id = R.string.button_text))
        }

        // 点击按钮后显示的文本
        if (showText) {
            Text(
                text = stringResource(id = R.string.clicked_message),
                modifier = Modifier.padding(top = 16.dp)
            )
        }
    }
}

@Preview(showBackground = true, name = "English Preview")
@Composable
fun PreviewEnglish() {
    MainScreen()
}

@Preview(showBackground = true, name = "Chinese Preview", locale = "zh")
@Composable
fun PreviewChinese() {
    MainScreen()
}

@Preview(showBackground = true, name = "Spanish Preview", locale = "es")
@Composable
fun PreviewSpanish() {
    MainScreen()
}
